﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PHTShop.admin
{
    public partial class delete : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             DataContextDataContext dc = new DataContextDataContext();
            if (!IsPostBack)
            {
               string s= Request.QueryString["id"];
               string partnerId = Request.QueryString["idPartner"];
                if (!string.IsNullOrEmpty(s))
                {
                    int id = Convert.ToInt32(s);
                    var photo = dc.ProductsPhotos.SingleOrDefault(z => z.id == id);
                    dc.ProductsPhotos.DeleteOnSubmit(photo);
                    dc.SubmitChanges();
                   Server.Transfer("editProduct.aspx?id="+photo.Product.id.ToString());
                }

                if (!string.IsNullOrEmpty("idPartner"))
                {
                    int id = Convert.ToInt32(partnerId);
                    var products = dc.Products.Where(z => z.PartnersId == id).ToList();
                    var part = dc.Partners.SingleOrDefault(z => z.id == id);
                    if (products.Count > 0)
                    {
                        part.status = false;
                    }
                    else {
                        dc.Partners.DeleteOnSubmit(part);
                    }
                    dc.SubmitChanges();
                    Server.Transfer("createPartner.aspx");
                    
                }
                
            }
        }
    }
}